package com.example.firstdemo

import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Spinner
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class TextViewActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_text_view)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        // 获取布局中的下拉控件
        val citySpinner: Spinner = findViewById<Spinner>(R.id.citySpinner)
// 定义下拉选项数据源
        val cities = arrayOf("请选择城市", "北京", "上海", "广州", "深圳", "杭州", "成都")
// 创建适配器并设置条目布局
        val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, cities)
// 设置下拉展开时的列表样式
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
// 将适配器绑定到下拉控件
        citySpinner.adapter = adapter
    }
}